#include<bits/stdc++.h>
using namespace std;
int T;
int n, m, l, V;
const int MAXN = 1e5 + 10;
int d[MAXN], v[MAXN], a[MAXN];
int p[MAXN];
const int MAXL = 1e6 + 10;
struct node
{
    int l, r;
}t[MAXN], q[MAXN];
int tot, cnt;
bool operator<(const node& a, const node& b)
{
    return a.l == b.l ? a.r > b.r : a.l < b.l;
}
int tr[MAXN];
inline int lowbit(int x)
{
    return x & -x;
}
void add(int x)
{
    while (x <= m)
    {
        tr[x]++;
        x += lowbit(x);
    }
}
int ask(int x)
{
    int ret = 0;
    while (x)
    {
        ret += tr[x];
        x -= lowbit(x);
    }
    return ret;
}
inline bool chk(int i, int j)
{
    return V * V < v[i] * v[i] + 2 * a[i] * (p[j] - d[i]);
}
inline void newnode(int l, int r)
{
    t[++tot] = {l, r};
}
int fnd(int x)
{
    int l = 1, r = m;
    while (l < r)
    {
        int mid = (l + r) >> 1;
        if (p[mid] >= x) r = mid;
        else l = mid + 1;
    }
    return l;
}
int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> T;
    while (T--)
    {//cerr << T << endl;
        cin >> n >> m >> l >> V;
        for(int i = 1; i <= n; ++i) cin >> d[i] >> v[i] >> a[i];
        for(int i = 1; i <= m; ++i) cin >> p[i];
        tot = cnt = 0;
        int ans1 = 0, ans2 = m;
        //for(int i = 1; i <= m; ++i) cout << p[i] << ' ';
        for(int i = 1; i <= n; ++i)
        {
            if (p[m] < d[i]) continue;
            int pos = fnd(d[i]);
            //cout << i << " " << pos << "\n";
            if (a[i] == 0)
            {
                if (v[i] <= V) continue;
                ans1++;
                newnode(pos, m);//cout << i << " " << pos << "\n";
                continue;
            }
            int l = pos, r = m;
            if (a[i] > 0)
            {
                if (!chk(i, m)) continue;
                ans1++;
                while (l < r)
                {
                    int mid = (l + r) >> 1;
                    if (chk(i, mid)) r = mid;
                    else l = mid + 1;
                }//cout << i << " " << l << "\n";
                newnode(l, m);
            }
            else
            {
                if (!chk(i, pos)) continue;
                ans1++;
                while (l < r)
                {
                    int mid = (l + r + 1) >> 1;
                    if (chk(i, mid)) l = mid;
                    else r = mid - 1;
                }
                newnode(pos, l);//cout << i << " " << l << "\n";
            }
        }
        sort(t + 1, t + tot + 1);
        //for(int i = 1; i <= tot; ++i) cout << t[i].l << ' ' << t[i].r << '\n';
        int i = tot;
        while (i)
        {
            q[++cnt] = t[i]; 
            int j = i - 1;
            while (j && t[j].l <= t[i].l && t[i].r <= t[j].r) --j;
            i = j;
        }
       // for(int i = 1; i <= cnt; ++i) cout << q[i].l << " " << q[i].r << "\n";
        memset(tr, 0, sizeof tr);
        for(int i = 1; i <= cnt; ++i)
        {
            //cout << ask(q[i].r) << ' ' << ask(q[i].l - 1) << '\n';
            if (ask(q[i].r) - ask(q[i].l - 1)) continue;
            add(q[i].l);
            --ans2;
        }
        cout << ans1 << ' ' << ans2 << '\n';
    }
    return 0;
}